﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace WcfFlashRemoting.IO.Writers
{
    internal abstract class AmfBaseWriter
    {
        protected BinaryWriter writer;
        public AmfBaseWriter(BinaryWriter writer)
        {
            this.writer = writer;
        }

        public void WriteAmfMessage(WcfFlashRemoting.AmfObjects.AmfMessage resultMessage)
        {
            writer.Write((ushort)resultMessage.Headers.Count);
            for (int i = 0; i < resultMessage.Headers.Count; i++)
            {
                WriteAmfHeader(resultMessage.Headers[i]);
            }
            writer.Write((ushort)resultMessage.Body.Count);
            for (int i = 0; i < resultMessage.Body.Count; i++)
            {
                WriteAmfBody(resultMessage.Body[i]);
            }
        }

        protected abstract void WriteAmfHeader(AmfObjects.AmfHeader header);
        protected abstract void WriteAmfBody(AmfObjects.AmfBody body);
    }
}
